﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using DA;

namespace qlhocsinh
{
    public partial class Frlapbaocaotongket : Form
    {
        private baocaotongket_DA _baoCaoTongKetMon;
        private danhsachmonhoc _danhSachMonHoc;
      

        public Frlapbaocaotongket()
        {
            InitializeComponent();
            _baoCaoTongKetMon = new baocaotongket_DA();
           _danhSachMonHoc = new danhsachmonhoc();
           combo();
           comboMH();
           
           
        }
        void comboMH()
        {
            DataLINQHocSinhDataContext dt = new DataLINQHocSinhDataContext();
            var cb = dt.GetTable<MONHOC>();


            cbmon.DataSource = cb;
            cbmon.DisplayMember = "TENMH";
            cbmon.ValueMember = "MAMH";

        }
        void combo()
        {
            DataLINQHocSinhDataContext dt = new DataLINQHocSinhDataContext();
            var cb = (from a in dt.BANGDIEMs select new {  a.MAHK }).Distinct().ToList();
            cbhocky.DataSource = cb;
            cbhocky.DisplayMember = "MAHK";
            cbhocky.ValueMember = "MAHK";

        }
       
        private void Frlapbaocaotongket_Load(object sender, EventArgs e)
        {
          cbmon.DataSource = _danhSachMonHoc.LayDSMonHoc();
            //string HocKy = cbhocky.Text.ToString().Substring(cbhocky.Text.ToString().Length - 1, 1);
          LoadGridView();
        }

        private void LoadGridView()
        {
            try
            {
                dataGridView1.DataSource = _baoCaoTongKetMon.LoadDSTongKetMonHoc(cbmon.SelectedValue.ToString(), cbhocky.SelectedValue.ToString());
            }
            catch
            {
                MessageBox.Show("Xảy ra lỗi trong quá trình lấy dữ liệu, hãy kiểm tra lại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult traloi;
            traloi = MessageBox.Show("Chắc không?", "Trả lời",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (traloi == DialogResult.OK)
                Application.Exit();
        }

        private void cbhocky_SelectionChangeCommitted(object sender, EventArgs e)
        {
            LoadGridView();
        }

        private void cbmon_SelectionChangeCommitted(object sender, EventArgs e)
        {
            LoadGridView();
        }
    }
}
